<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>撤消变更计划</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <input type="hidden" id="sheetId" name="sheetId" th:value="${sheet.id}">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-status">接收状态</label>
                                    <select id="query-status" class="form-control" name="recMark">
                                        <option value="" selected>请选择</option>
                                        <option value="0">未接收</option>
                                        <option value="1">已接收</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <h4>
                        项目编号:[[${sheet.proCode}]]&nbsp;&nbsp;&nbsp;&nbsp;
                        项目名称:[[${sheet.proName}]]&nbsp;&nbsp;&nbsp;&nbsp;
                        项目数量:[[${sheet.proNum}]]&nbsp;&nbsp;&nbsp;&nbsp;
                        类型:[[${sheet.malType}]]&nbsp;&nbsp;&nbsp;&nbsp;
                        部分:[[${sheet.part}]]&nbsp;&nbsp;&nbsp;&nbsp;
                    </h4>
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<input type="hidden" id="reportType" th:value="${sheet.reportType}">
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table, columns,
        sheetId = +$("#sheetId").val(),
        reportType = +$("#reportType").val();

    /** 选择计划提报类型 */
    function handlerPage() {
        switch (reportType) {
            case 1:
                columns = [
                    {title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {title: "原物料描述", field: 'malDesc'},
                    {title: "原数量", field: 'num'},
                    {title: "原单位", field: 'unit'},
                    {title: "原型号/标准号", field: 'standard'},
                    {title: "原品牌", field: 'brand'},
                    {title: "原备注", field: 'remark'},
                    {title: "原附件", field: 'url',
                        formatter: function (value) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                            return '';
                        }
                    },
                    {title: "新物料描述", field: 'afterMalDesc',
                        formatter: function (value, row) {
                            if (value === row.malDesc) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新数量", field: 'afterNum',
                        formatter: function (value, row) {
                            if (value === row.num) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新单位", field: 'afterUnit',
                        formatter: function (value, row) {
                            if (value === row.unit) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新型号/标准号", field: 'afterStandard',
                        formatter: function (value, row) {
                            if (value === row.standard) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新品牌", field: 'afterBrand',
                        formatter: function (value, row) {
                            if (value === row.brand) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新备注", field: 'afterRemark',
                        formatter: function (value, row) {
                            if (value === row.remark) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新附件", field: 'afterUrl',
                        formatter: function (value, row) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                        }
                    },
                    {title: "接收状态", field: 'recMark',
                        formatter: function (value) {
                            if (value === 0) {
                                return '<span class="badge label-inverse">未接收</span>';
                            } else if (value === 1) {
                                return '<span class="badge label-success">已接收</span>';
                            }
                        }
                    },
                    {title: "接收时间", field: 'changeRecTime'},
                    {
                        title: "操作",
                        formatter: function (value, row) {
                            let actions = [];
                            if (row.recMark === 0 && row.alreadyChange !== 1) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelChange(' + row.id + ')"> 撤消并删除</a>');
                            }
                            return actions.join('');
                        }
                    }
                ];
                break;
            case 2:
                columns = [
                    {title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {title: "原物料描述", field: 'malDesc'},
                    {title: "原图号", field: 'diagram'},
                    {title: "原数量", field: 'num'},
                    {title: "原单位", field: 'unit'},
                    {title: "原外协类型", field: 'assistType'},
                    {title: "原备注", field: 'remark'},
                    {title: "原附件", field: 'url',
                        formatter: function (value) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                            return '';
                        }
                    },
                    {title: "新物料描述", field: 'afterMalDesc',
                        formatter: function (value, row) {
                            if (value === row.malDesc) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新图号", field: 'afterDiagram',
                        formatter: function (value, row) {
                            if (value === row.diagram) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新数量", field: 'afterNum',
                        formatter: function (value, row) {
                            if (value === row.num) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新单位", field: 'afterUnit',
                        formatter: function (value, row) {
                            if (value === row.unit) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新外协类型", field: 'afterAssistType',
                        formatter: function (value, row) {
                            if (value === row.assistType) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新备注", field: 'afterRemark',
                        formatter: function (value, row) {
                            if (value === row.remark) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新附件", field: 'afterUrl',
                        formatter: function (value, row) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                        }
                    },
                    {title: "接收状态", field: 'recMark',
                        formatter: function (value) {
                            if (value === 0) {
                                return '<span class="badge label-inverse">未接收</span>';
                            } else if (value === 1) {
                                return '<span class="badge label-success">已接收</span>';
                            }
                        }
                    },
                    {title: "接收时间", field: 'changeRecTime'},
                    {
                        title: "操作",
                        formatter: function (value, row) {
                            let actions = [];
                            if (row.recMark === 0 && row.alreadyChange !== 1) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelChange(' + row.id + ')"> 撤消</a>');
                            }
                            return actions.join('');
                        }
                    }
                ];
                break;
            case 3:
                columns = [
                    {title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {title: "原物料描述", field: 'malDesc'},
                    {title: "原数量", field: 'num'},
                    {title: "原单位", field: 'unit'},
                    {title: "原型号/标准号", field: 'standard'},
                    {title: "原材质", field: 'quality'},
                    {title: "原使用库存", field: 'useStore',
                        formatter: function (value) {
                            if (value === 1) {
                                return '<span class="badge label-success">是</span>';
                            } else if (value === 2) {
                                return '<span class="badge label-inverse">否</span>';
                            }
                        }
                    },
                    {title: "原备注", field: 'remark'},
                    {title: "原附件", field: 'url',
                        formatter: function (value) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                            return '';
                        }
                    },
                    {title: "新物料描述", field: 'afterMalDesc',
                        formatter: function (value, row) {
                            if (value === row.malDesc) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新数量", field: 'afterNum',
                        formatter: function (value, row) {
                            if (value === row.num) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新单位", field: 'afterUnit',
                        formatter: function (value, row) {
                            if (value === row.unit) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新型号/标准号", field: 'afterStandard',
                        formatter: function (value, row) {
                            if (value === row.standard) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新材质", field: 'afterQuality',
                        formatter: function (value, row) {
                            if (value === row.quality) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新使用库存", field: 'afterUseStore',
                        formatter: function (value, row) {
                            if (value === row.useStore) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新备注", field: 'afterRemark',
                        formatter: function (value, row) {
                            if (value === row.remark) {
                                return '';
                            } else {
                                return '<span class="text-red">' + value + '</span>';
                            }
                        }
                    },
                    {title: "新附件", field: 'afterUrl',
                        formatter: function (value, row) {
                            if (value) {
                                return '<a target="_blank" href="' + value + '">下载</a>'
                            }
                        }
                    },
                    {title: "接收状态", field: 'recMark',
                        formatter: function (value) {
                            if (value === 0) {
                                return '<span class="badge label-inverse">未接收</span>';
                            } else if (value === 1) {
                                return '<span class="badge label-success">已接收</span>';
                            }
                        }
                    },
                    {title: "接收时间", field: 'changeRecTime'},
                    {
                        title: "操作",
                        formatter: function (value, row) {
                            let actions = [];
                            if (row.recMark === 0 && row.alreadyChange !== 1) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelChange(' + row.id + ')"> 撤消</a>');
                            }
                            return actions.join('');
                        }
                    }
                ];
                break;
        }
    }

    function cancelChange(id) {
        js.modal.confirm("确认撤消吗？", function () {
            js.post({
                url: ctx + "report/check/cancel",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                        js.table.refresh(table);
                    }
                }
            })
        })
    }

    $(function () {

        debugger;
        handlerPage();

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "report/check/change/list",
            showExport: false,
            columns: columns
        });

    });
</script>
</body>
</html>
